package com.ssh.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ssh.dao.UserDao;
import com.ssh.entity.Category;
import com.ssh.entity.Commodity;
import com.ssh.entity.User;
import com.ssh.entity.vo.CategoryVo;
import com.ssh.entity.vo.CommodityVo;
import com.ssh.service.UserService;

/**
 * 服务层 做业务逻辑和数据中转
 * @author Administrator
 *
 */
@Service
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserDao userDao;

	public User loadUserByName(String userName) {
		return userDao.loadUserByName(userName);
	}
	
	/**
	 * 通过parentid查询该栏目的所有子栏目
	 * @param parentid
	 * @return
	 */
	public List<CategoryVo> findCategorysByParentid(int parentid){
		List<CategoryVo> volist = new ArrayList<CategoryVo>();
		CategoryVo cvo = null;
		List<Category> list = userDao.findCategorysByParentid(parentid);
		if(null != list && list.size() > 0){
			for(Category c : list){
				cvo = new CategoryVo();
				BeanUtils.copyProperties(c, cvo);
				volist.add(cvo);
			}
		}
		return volist;
	}
	public List<CommodityVo> findCommoditysByC3id(int c3id){
		List<CommodityVo> volist = new ArrayList<CommodityVo>();
		CommodityVo cvo =null;
		List<Commodity> list = userDao.findCommoditysByC3id(c3id);
		if(null != list&&list.size()>0){
			for(Commodity c:list){
				cvo = new CommodityVo();
				BeanUtils.copyProperties(c, cvo);
				volist.add(cvo);
			}
			
		}
		
		return volist;
	}

}
